﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Test.aspx.cs" Inherits="WebTestharness.Test" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Test harness , Any Web Service on internet !
    </h2>
    <p>
        You can test web service available on internet.The demostration is on Weather Web
        Serice found at <a href="http://www.deeptraining.com/webservices/weather.asmx" title="Weather">
            Weather</a>. However, you can change it to any web service.
    </p>
    <div style="border: 1px solid silver; margin: 10,10,10,10; padding: 10 10 10 10">
        <fieldset>
            <p>
                Web Site URL :
            </p>
            <p>
                <asp:Label ID="lblInvokedResult" runat="server" ForeColor="Red" BackColor="AliceBlue"></asp:Label>
            </p>
            <p>
                <asp:TextBox ID="txtUrl" runat="server" Width="464px">http://www.deeptraining.com/webservices/weather.asmx?WSDL</asp:TextBox>
                <asp:Button ID="btnGetWSDL" runat="server" Text="Get Proxy" OnClick="btnGetWSDL_Click" />
            </p>
            <div id="MemberDiv" runat="server">
                <asp:Label ID="lblDynamicResult" runat="server" ForeColor="Red" BackColor="AliceBlue"></asp:Label>
                <a id="linkGetWSDL" runat="server" visible="false" href="#" onclick="ManageWebWSDL(this)">
                    GetMembers</a>
            </div>
        </fieldset>
    </div>
    <p>
        You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
    </p>
    <script type="text/javascript">
        //OnClick="btnGetMembers_Click"
        function ManageWebWSDL(caller) {
            var wsdl = document.getElementById("ctl00$MainContent$txtUrl").value;
            var members = PageMethods.GetWebMethodNames(wsdl, OnSucceededCallback, OnFailedCallback, caller);


        }
        function OnSucceededCallback(data, caller) {
            var table = document.createElement("table");
            var tobody = document.createElement("tbody");

            table.setAttribute("border", "1");
            table.appendChild(tobody);

            var tr = document.createElement("tr");
            var td1 = document.createElement("td");
            var td2 = document.createElement("td");


            tobody.appendChild(tr);

            tr.appendChild(td1);
            tr.appendChild(td2);

            td1.innerHTML = "ReturnType";
            td2.innerHTML = "Function Name";

            try {

                for (var i = 0; i < data.length; i++) {
                    var itr = document.createElement("tr");
                    var itd1 = document.createElement("td");
                    var itd2 = document.createElement("td");
                    itd1.innerHTML = data[i].ReturnType;
                    itd2.innerHTML = "<a href='#' onclick='GetForm(this,\"" + data[i].Name + "\" ) '> " + data[i].Name + "</a>";
                    itr.appendChild(itd1);
                    itr.appendChild(itd2);
                    tobody.appendChild(itr);
                }
                caller.parentNode.appendChild(table);
            }
            catch (e) {
            }

        }
        function OnFailedCallback(data) {
            alert("f");
        }

        function GetForm(caller, methodName) {
            var d = document.createElement("div");
            d.innerHTML = "FORM to be generated for " + methodName;
            caller.parentNode.appendChild(d);
            PageMethods.GetWebMethodParameters(methodName, OnSucceededMemberCallback, OnFailedMemberCallback, caller);
 
        }

        function OnSucceededMemberCallback(data, caller) {
            var table = document.createElement("table");
            var tobody = document.createElement("tbody");
            table.setAttribute("border", "1");
            table.appendChild(tobody);


            var tr = document.createElement("tr");
            var td1 = document.createElement("td");
            var td2 = document.createElement("td");
            var td3 = document.createElement("td");
            var td4 = document.createElement("td");


            tobody.appendChild(tr);

            tr.appendChild(td1);
            tr.appendChild(td2);
            tr.appendChild(td3);
            tr.appendChild(td4);

            td1.innerHTML =  data[0].ReturnType;
            td2.innerHTML =  data[0].MethodName;
            td3.innerHTML = "<input type='button' onclick='WebInvoke(\"" +  data[0].MethodName + "\")' value='Invoke Method' />";
            td4.innerHTML = "TRY...";

            try {

                for (var i = 0; i < data[0].Parameters.length; i++) {
                    var itr = document.createElement("tr");
                    var itd1 = document.createElement("td");
                    var itd2 = document.createElement("td");
                    var itd3 = document.createElement("td");
                    var itd4 = document.createElement("td");

                    itd1.innerHTML = "Enter " + data[0].Parameters[i].ParameterType + " " + data[0].Parameters[i].ParameterName;
                    itd2.innerHTML = "<input type='text' id='txt" + data[0].Parameters[i].ParameterName + "_" + data[0].Parameters[i].Position + "' />";
                    itd3.innerHTML = "<input type='checkbox' id='chk" + data[0].Parameters[i].ParameterName + "_" + data[0].Parameters[i].Position + "' value='Out Parameter' />";
                    itd4.innerHTML = data[0].Parameters[i].Position;

                    //itd2.attributes("onclick", "GetForm('" + data.Name + "',this);");

                    tobody.appendChild(itr);

                    itr.appendChild(itd1);
                    itr.appendChild(itd2);
                    itr.appendChild(itd3);
                    itr.appendChild(itd4);
                }
                caller.parentNode.appendChild(table);
            }
            catch (e) {
            }

        }
        function OnFailedMemberCallback(data) {
            alert("cf");

        }

        function WebInvoke(methodName) {

        }
        function OnSucceededInvokCallback(data, caller) {
            
        }
        function OnFailedInvokCallback(data) {
            alert("cfi");

        }
    </script>
</asp:Content>
